/*   Copyright 2012 Julian Aloofi

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef TACTICUS_RESOURCEMANAGER_HPP
#define TACTICUS_RESOURCEMANAGER_HPP

#include <string>
#include <map>
#include <utility>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Text.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/shared_ptr.hpp>

#include "Exceptions.hpp"
#include "Interface/WindowManager.hpp"

namespace Tacticus
{

class ResourceManager
{
private:
    static ResourceManager *instance;
    std::string filesystemBasePath;
    bool resourcesLoaded;
    const std::string smallSuffix;
    std::map<std::string, sf::Texture> textureMap;
    std::map<std::pair<std::string, int>, sf::Texture> fontTextureMap;
    std::map<std::string, float> smallTextureMap;
    sf::Font mainFont;
    sf::Vector2f neededSpriteScale;
public:
    static ResourceManager &getInstance();
    static void destroy();
    void setFilesystemBasePath(std::string newFilesystemBasePath);
    boost::shared_ptr<sf::Sprite> getSprite(std::string textureName) const;
    boost::shared_ptr<sf::Text> renderText(std::string desiredText,
        int textSize = 150) const;
    void loadResources();
    void unloadResources();
private:
    ResourceManager();
    ResourceManager(const ResourceManager&) {}
    ~ResourceManager();
};

}

#endif
